home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / ghostscript / 8.64 / Resource / Init / gs_pdfwr.ps < prev    next >
Encoding:
Text File  |  2009-04-17  |  27.0 KB  |  875 lines

  1. %    Copyright (C) 1996, 2000 Aladdin Enterprises.  All rights reserved.
  2. % This software is provided AS-IS with no warranty, either express or
  3. % implied.
  4. % This software is distributed under license and may not be copied,
  5. % modified or distributed except as expressly authorized under the terms
  6. % of the license contained in the file LICENSE in this distribution.
  7. % For more information about licensing, please refer to
  8. % http://www.ghostscript.com/licensing/. For information on
  9. % commercial licensing, go to http://www.artifex.com/licensing/ or
  10. % contact Artifex Software, Inc., 101 Lucas Valley Road #110,
  11. % San Rafael, CA  94903, U.S.A., +1(415)492-9861.
  12.  
  13. % $Id: gs_pdfwr.ps 8954 2008-08-08 04:22:38Z ray $
  14. % PDF writer additions to systemdict.
  15.  
  16. % This file should be included iff the pdfwrite "device" is included
  17. % in the executable.
  18.  
  19. % ---------------- Predefined configurations ---------------- %
  20.  
  21. % These correspond to the 4 predefined settings in Acrobat Distiller 5,
  22. % plus a "default" setting that doesn't downsample images.
  23.  
  24. /.a2112 [2 1 1 2] readonly def
  25. /.a1111 [1 1 1 1] readonly def
  26. /.standardfonts [
  27.   /Courier /Courier-Bold /Courier-Oblique /Courier-BoldOblique
  28.   /Helvetica /Helvetica-Bold /Helvetica-Oblique /Helvetica-BoldOblique
  29.   /Times-Roman /Times-Bold /Times-Italic /Times-BoldItalic
  30.   /Symbol /ZapfDingbats
  31. ] readonly def
  32.  
  33. % Parameters common to all non-default configurations.
  34. % Note that the default configuration overrides a few of these.
  35. /.defaultImageDict mark
  36.   /QFactor 0.9 /Blend 1
  37.   /HSamples .a2112 /VSamples .a2112
  38. .dicttomark readonly def
  39. /.distillercommon mark
  40.   /AlwaysEmbed []
  41.   /AntiAliasColorImages false
  42.   /AntiAliasGrayImages false
  43.   /AntiAliasMonoImages false
  44.   /ASCII85EncodePages false
  45.   /AutoFilterColorImages true
  46.   /AutoFilterGrayImages true
  47.   /AutoPositionEPSFiles true
  48.   /Binding /Left
  49.   /CalCMYKProfile (None)        % (U.S. Web Coated (SWOP) v2)
  50.   /CalGrayProfile (None)        % (Dot Gain 20%)  
  51.   /CalRGBProfile (None)            % (sRGB IEC61966-2.1)
  52.   /ColorImageDepth -1
  53.   /ColorImageDict .defaultImageDict
  54.   /ColorImageDownsampleThreshold 1.5
  55.   /ColorImageFilter /DCTEncode
  56.   /CompressPages true
  57.   /ConvertImagesToIndexed true
  58.   /DefaultRenderingIntent /Default
  59.   /DetectBlends true
  60.   /DownsampleColorImages true
  61.   /DownsampleGrayImages true
  62.   /DownsampleMonoImages true
  63.   /EmitDSCWarnings false
  64.   /EncodeColorImages true
  65.   /EncodeGrayImages true
  66.   /EncodeMonoImages true
  67.   /EndPage -1
  68.   /GrayImageDepth -1
  69.   /GrayImageDict .defaultImageDict
  70.   /GrayImageDownsampleThreshold 1.5
  71.   /GrayImageFilter /DCTEncode
  72.   /ImageMemory 524288
  73.   /LockDistillerParams false
  74.   /MaxSubsetPct 100
  75.   /MonoImageDepth -1
  76.   /MonoImageDict mark
  77.     /K -1
  78.   .dicttomark readonly
  79.   /MonoImageDownsampleThreshold 1.5
  80.   /MonoImageFilter /CCITTFaxEncode
  81.   /OffOptimizations 0
  82.   /OPM 1
  83.   /Optimize true
  84.   /ParseDSCComments true
  85.   /ParseDSCCommentsForDocInfo true
  86.   /PDFXTrimBoxToMediaBoxOffset [0 0 0 0]
  87.   /PDFXSetBleedBoxToMediaBox true
  88.   /PDFXBleedBoxToTrimBoxOffset [0 0 0 0]
  89.   /PreserveCopyPage true
  90.   /PreserveHalftoneInfo false
  91.   /sRGBProfile (None)            % (sRGB IEC61966-2.1)
  92.   /StartPage 1
  93.   /SubsetFonts true
  94.   /TransferFunctionInfo /Preserve
  95.   /UseFlateCompression true
  96.   /UsePrologue false
  97. .dicttomark readonly def
  98.  
  99. /.distillersettings mark
  100.  
  101. /default mark
  102.   /AutoRotatePages /PageByPage
  103.   /CannotEmbedFontPolicy /Warning
  104.   /ColorACSImageDict .defaultImageDict
  105.   /ColorConversionStrategy /LeaveColorUnchanged
  106. %  /ColorImageDownsampleType
  107. %  /ColorImageResolution
  108. %  /CompatibilityLevel
  109.   /CreateJobTicket false
  110.   /DoThumbnails false
  111.   /DownsampleColorImages false        % override
  112.   /DownsampleGrayImages false        % override
  113.   /DownsampleMonoImages false        % override
  114.   /EmbedAllFonts true
  115.   /GrayACSImageDict .defaultImageDict
  116. %  /GrayImageDownsampleType
  117. %  /GrayImageResolution
  118. %  /MonoImageDownsampleType
  119. %  /MonoImageResolution
  120.   /NeverEmbed .standardfonts
  121.   /Optimize false            % override
  122.   /PreserveEPSInfo true
  123.   /PreserveOPIComments true
  124.   /PreserveOverprintSettings true
  125.   /UCRandBGInfo /Preserve
  126. .dicttomark readonly
  127.  
  128. /.screenACSImageDict mark
  129.   /QFactor 0.76 /Blend 1 /ColorTransform 1
  130.   /HSamples .a2112 /VSamples .a2112
  131. .dicttomark readonly def
  132. /screen mark
  133.   /AutoRotatePages /PageByPage
  134. %  /CalGrayProfile (None)
  135.   /CannotEmbedFontPolicy /Warning
  136.   /ColorACSImageDict .screenACSImageDict
  137.   /ColorConversionStrategy /sRGB
  138.   /ColorImageDownsampleType /Average
  139.   /ColorImageResolution 72
  140.   /CompatibilityLevel 1.3
  141.   /CreateJobTicket false
  142.   /DoThumbnails false
  143.   /EmbedAllFonts true
  144.   /GrayACSImageDict .screenACSImageDict
  145.   /GrayImageDownsampleType /Average
  146.   /GrayImageResolution 72
  147.   /MonoImageDownsampleType /Average
  148.   /MonoImageResolution 300
  149.   /NeverEmbed .standardfonts
  150.   /PreserveEPSInfo false
  151.   /PreserveOPIComments false
  152.   /PreserveOverprintSettings false
  153.   /UCRandBGInfo /Remove
  154. .dicttomark readonly
  155.  
  156. /ebook mark
  157.   /AutoRotatePages /All
  158. %  /CalGrayProfile (None)
  159.   /CannotEmbedFontPolicy /Warning
  160.   /ColorACSImageDict .screenACSImageDict
  161.   /ColorConversionStrategy /sRGB
  162.   /ColorImageDownsampleType /Bicubic
  163.   /ColorImageResolution 150
  164.   /CompatibilityLevel 1.4
  165.   /CreateJobTicket false
  166.   /DoThumbnails false
  167.   /EmbedAllFonts true
  168.   /GrayACSImageDict .screenACSImageDict
  169.   /GrayImageDownsampleType /Bicubic
  170.   /GrayImageResolution 150
  171.   /MonoImageDownsampleType /Bicubic
  172.   /MonoImageResolution 300
  173.   /NeverEmbed .standardfonts
  174.   /PreserveEPSInfo false
  175.   /PreserveOPIComments false
  176.   /PreserveOverprintSettings false
  177.   /UCRandBGInfo /Remove
  178. .dicttomark readonly
  179.  
  180. /.printerACSImageDict mark
  181.   /QFactor 0.4 /Blend 1 /ColorTransform 1
  182.   /HSamples .a1111 /VSamples .a1111
  183. .dicttomark readonly def
  184. /printer mark
  185.   /AutoRotatePages /None
  186. %  /CalGrayProfile (None)
  187.   /CannotEmbedFontPolicy /Warning
  188.   /ColorACSImageDict .printerACSImageDict
  189.   /ColorConversionStrategy /UseDeviceIndependentColor
  190.   /ColorImageDownsampleType /Bicubic
  191.   /ColorImageResolution 300
  192.   /CompatibilityLevel 1.4
  193.   /CreateJobTicket true
  194.   /DoThumbnails false
  195.   /EmbedAllFonts true
  196.   /GrayACSImageDict .printerACSImageDict
  197.   /GrayImageDownsampleType /Bicubic
  198.   /GrayImageResolution 300
  199.   /MonoImageDownsampleType /Bicubic
  200.   /MonoImageResolution 1200
  201.   /NeverEmbed []
  202.   /PreserveEPSInfo true
  203.   /PreserveOPIComments true
  204.   /PreserveOverprintSettings true
  205.   /UCRandBGInfo /Preserve
  206. .dicttomark readonly
  207.  
  208. /.prepressACSImageDict mark
  209.   /QFactor 0.15 /Blend 1 /ColorTransform 1
  210.   /HSamples .a1111 /VSamples .a1111
  211. .dicttomark readonly def
  212. /prepress mark
  213.   /AutoRotatePages /None
  214.   /CannotEmbedFontPolicy /Error
  215.   /ColorACSImageDict .prepressACSImageDict
  216.   /ColorConversionStrategy /LeaveColorUnchanged
  217.   /ColorImageDownsampleType /Bicubic
  218.   /ColorImageResolution 300
  219.   /CompatibilityLevel 1.4
  220.   /CreateJobTicket true
  221.   /DoThumbnails true
  222.   /EmbedAllFonts true
  223.   /GrayACSImageDict .prepressACSImageDict
  224.   /GrayImageDownsampleType /Bicubic
  225.   /GrayImageResolution 300
  226.   /MonoImageDownsampleType /Bicubic
  227.   /MonoImageResolution 1200
  228.   /NeverEmbed []
  229.   /PreserveEPSInfo true
  230.   /PreserveOPIComments true
  231.   /PreserveOverprintSettings true
  232.   /UCRandBGInfo /Preserve
  233. .dicttomark readonly
  234.  
  235. % Define distiller settings for the ps2write device and for the ps2ps2 script :
  236. /PSL2Printer mark
  237.   /AutoRotatePages /None
  238.   /CannotEmbedFontPolicy /Error
  239.   /ColorACSImageDict .prepressACSImageDict
  240.   /ColorConversionStrategy /LeaveColorUnchanged
  241.   /ColorImageDownsampleType /Bicubic
  242.   /ColorImageResolution 600
  243.   /CompatibilityLevel 1.2 % Always 1.2 with ps2write.
  244.   % /CreateJobTicket true % Not sure
  245.   /DoThumbnails false
  246.   /EmbedAllFonts true
  247.   /GrayACSImageDict .prepressACSImageDict
  248.   /GrayImageDownsampleType /Bicubic
  249.   /GrayImageResolution 600
  250.   /MonoImageDownsampleType /Bicubic
  251.   /MonoImageResolution 1200
  252.   /NeverEmbed []
  253.   /PreserveEPSInfo true
  254.   /PreserveOPIComments true
  255.   /PreserveOverprintSettings true
  256.   /UCRandBGInfo /Preserve
  257.  
  258.   /PreserveHalftoneInfo true 
  259.   /TransferFunctionInfo /Preserve 
  260.   /MaxViewerMemorySize 8000000 
  261.   /CompressPages false 
  262.   /CompressFonts false 
  263.   /ASCII85EncodePages true 
  264. .dicttomark readonly
  265.  
  266. .dicttomark readonly def
  267.  
  268. % ---------------- End of predefined configurations ---------------- %
  269.  
  270. % Set optimizations for converting PostScript to PDF.
  271. % The ps2pdf* scripts invoke this.
  272. /.setpdfwrite {        % - .setpdfwrite -
  273.         % Set a large VM threshold to reduce garbage collection.
  274.   currentuserparams /VMThreshold get 3000000 .max setvmthreshold
  275. } bind def
  276.  
  277. % ---------------- pdfmark and DSC processing ---------------- %
  278.  
  279. /.write_small_positive_real  % <file> <real> .write_small_positive_real -
  280. { % The argument must be grater than 0 and must be strongly samller than 0.1.
  281.   % The conversion isn't simple due to the low (24 bits) precision 
  282.   % of the floating point arithmetics in Postscript.
  283.   % For best result we first use the 1e8 factor since its binary 
  284.   % representation 101111101011110000100000000 well rounds into 14 significant
  285.   % bits :         101111101011110000000000000 .
  286.   1 index (.) writestring
  287.   { dup 100000000 mul 
  288.     dup 10 mul 1 ge {
  289.       % Will need not greater than 0.1 due to a rounding below.
  290.       pop exit
  291.     } if
  292.     exch pop
  293.     1 index (00000000) writestring
  294.   } loop
  295.   % Now it is not smaller than 1e-9, use simple digitizing.
  296.   { dup 10 mul 
  297.     dup 10 mul 1 ge { 
  298.       pop exit 
  299.     } if
  300.     exch pop
  301.     1 index (0) writestring
  302.   } loop
  303.   % Now 0.01 <= n < 0.1, but rounding may give 0.1 .
  304.   % Convert to integer with 7 digits precision :
  305.   100000000 % precision factor 1e8       % f n r
  306.   dup 10 idiv 3 1 roll mul 0.5 add cvi   % f r' N
  307.   2 copy le {
  308.     % The rounding overflows, suppress it.
  309.     % Note it carries out an additional digit,
  310.     % that's why we needed <0.1 above.
  311.     pop pop (1) writestring
  312.   } {
  313.     % Didn't cary out, put 0.
  314.     2 index (0) writestring
  315.     exch                                 % f N r
  316.     % Continue the simple digitizing :
  317.     { 10 idiv dup                        % f N r' r'
  318.       2 index exch idiv                  % f N r' d
  319.       (0123456789) exch 1 getinterval    % f N r' (d)
  320.       3 index exch writestring           % f N r'
  321.       dup 3 2 roll exch mod              % f r' N'
  322.       dup 0 eq { 
  323.         % Don't write trailing zeros.
  324.         exit 
  325.       } if
  326.       exch                               % f N' r'
  327.     } loop
  328.     pop pop pop
  329.   } ifelse
  330. } bind def
  331.  
  332. % Encode values to pass for the /pdfmark or /DSC pseudo-parameter.
  333. /.pdf===dict mark
  334.   /arraytype
  335.    { dup xcheck { ({) (}) } { ([) (]) } ifelse
  336.         % Stack: file obj left right
  337.       4 1 roll 2 index exch writestring () exch
  338.        { exch 2 index exch writestring
  339.      1 index exch pdf===only ( )
  340.        }
  341.       forall pop exch writestring
  342.    } bind
  343.   /packedarraytype 1 index
  344.   /dicttype
  345.    { 1 index (<<\n) writestring
  346.       { 2 index 3 -1 roll pdf===only 1 index ( ) writestring
  347.     1 index exch pdf===only dup (\n) writestring
  348.       }
  349.      forall (>>) writestring
  350.    } bind
  351.   /nametype {
  352.     % If the name string includes any non-regular characters,
  353.     % write it with two preceding and one following null character(s).
  354.     % (Null characters in the name itself are not allowed.)
  355.     % This non-standard escape convention is required for passing names
  356.     % that include non-regular characters, because PostScript provides
  357.     % no way to do this.  The pdf_scan_token procedure in the C code of
  358.     % the pdfwrite driver is currently the only place that recognizes
  359.     % this convention.
  360.     % Note that \004 may be self-delimiting in gs, but is not in standard PS.
  361.     dup .namestring (\000\004\011\012\014\015 %()/<>[]{}) .stringbreak null ne {
  362.       dup .namestring (\000) .stringbreak null ne {
  363.     /rangecheck signalerror
  364.       } if
  365.       1 index <0000> writestring 1 index exch write===only 0 write
  366.     } {
  367.       write===only
  368.     } ifelse
  369.   } bind
  370.   /realtype {
  371.     % Prevent using floating point format - see Bug 688167.
  372.     dup dup 0 lt { neg } if 0.01 lt {
  373.       dup 0 eq {
  374.         pop (0) writestring
  375.       } {
  376.         dup 0 lt {
  377.           1 index (-) writestring neg
  378.         } if
  379.         .write_small_positive_real
  380.       } ifelse
  381.     } {
  382.       write===only
  383.     } ifelse
  384.   } bind
  385. .dicttomark readonly def
  386. /pdf===only {    % <file> <obj> pdf===only -
  387.   .pdf===dict 1 index type .knownget { exec } { write===only } ifelse
  388. } bind def
  389. /.pdfcvbuf 30 string def    % enough for most arguments
  390. userdict /.pdfcvstring () put
  391. /.pdfcvs {        % <obj> .pdfcvs <string>
  392.   currentglobal exch false .setglobal
  393.   /.pdfcvstring () store
  394.         % We can't handle long values yet.
  395.   { pop dup length 0 eq { pop } {
  396.       /.pdfcvstring .pdfcvstring 3 -1 roll concatstrings store
  397.     } ifelse //.pdfcvbuf
  398.   } /NullEncode filter dup 3 -1 roll pdf===only
  399.   closefile
  400.   .setglobal .pdfcvstring
  401. } bind def
  402.  
  403. % Redefine pdfmark to pass the data to the driver.
  404. % We use a pseudo-parameter named /pdfmark whose value is an array:
  405. %    /key1 (value1) ... (CTM) /type
  406. /.pdfputparams {    % -mark- <key1> <value1> ... .pdfputparams <result...>
  407.   currentdevice null false counttomark 1 add 3 roll
  408.         % Don't allow the page device to get cleared....
  409.   {.putdeviceparams} .currentpagedevice pop {.setpagedevice} 3 .execn
  410. } bind def
  411. % Convert relevant operands to strings in an array.
  412. /.pdfcvsloop {        % -mark- values ... markname start step .pdfcvsloop
  413.             %   [values ... ctm markname]
  414.    matrix currentmatrix .pdfcvs 4 1 roll
  415.    counttomark 1 add 2 roll 
  416.    counttomark .localvmarray astore exch pop
  417.    3 1 roll
  418.             % Stack: values start step
  419.    2 index length 3 sub { 2 copy 2 copy get .pdfcvs put pop } for
  420. } bind def
  421. /.pdfcvsall {        % -mark- values ... markname .pdfcvsall <<same>>
  422.   0 1 .pdfcvsloop
  423. } bind def
  424. /.pdfcvseven {        % -mark- key value ... markname .pdfcvseven <<same>>
  425.   1 2 .pdfcvsloop
  426. } bind def
  427. /.pdfcvsnone {        % -mark- values ... markname .pdfcvsnone <<same>>
  428.   100000 1 .pdfcvsloop
  429. } bind def
  430. /.pdfcvsfirst {        % -mark- first values ... markname .pdfcvsfirst<<same>>
  431.   .pdfcvsnone
  432.   dup 0 2 copy get .pdfcvs put
  433. } bind def
  434. % The procedures in the following dictionary are called with the entire
  435. % pdfmark operand list (including the pdfmark name) on the stack;
  436. % they may modify this ad lib.  They must call .pdfcvsxxx.
  437. /.pdfmarkparams mark
  438.     % Unpack a dictionary for PUT, and don't convert stream data.
  439.   /PUT {
  440.     counttomark 3 eq {
  441.       1 index type /dicttype eq {
  442.     pop { } forall /.PUTDICT .pdfcvsall
  443.       } {
  444.     pop dup type /filetype eq {
  445.         % Read the file into a sequence of strings.
  446.         % This isn't great, but it's simple.
  447.       {
  448.         dup 64000 string readstring not { exch exit } if
  449.         exch
  450.       } loop closefile
  451.     } if
  452.     /.PUTSTREAM .pdfcvsfirst
  453.       } ifelse
  454.     } {
  455.       .pdfcvsall
  456.     } ifelse
  457.   } bind
  458.     % Unpack the array for PUTINTERVAL.
  459.   /PUTINTERVAL {
  460.     pop aload pop /.PUTINTERVAL .pdfcvsall
  461.   } bind
  462. .dicttomark readonly def
  463. /.pdfparamerror {    % ? ? ? -mark- ... <errname> <opname> .pdfparamerror -
  464.     counttomark 4 add 2 roll cleartomark pop pop pop
  465.     .systemvar exch signalerror
  466. } bind def
  467. /pdfmark {        % -mark- <key> <value> ... <markname> pdfmark -
  468.   dup /SP eq {
  469.     % A hack for synchronizing the clipping path.
  470.     gsave 
  471.     [1 0 0 1 0 0] setmatrix 0 setlinewidth
  472.     newpath -3 -3 moveto closepath stroke % Paints outside the device bbox.
  473.     grestore
  474.   } if
  475.   dup /PS eq systemdict /PDFX .knownget not { false } if 
  476.              systemdict /PDFA .knownget not { false } if or and {
  477.     % Execute it since PDF/X doesn't allow to embed it.
  478.     pop
  479.     { dup mark eq {
  480.         pop exit
  481.       } if
  482.       1 index /DataSource eq {
  483.         exch pop
  484.         cvx exec
  485.       } {
  486.         pop pop
  487.       } ifelse
  488.     } loop
  489.   } {
  490.     counttomark 1 add copy
  491.     //.pdfmarkparams 1 index .knownget { exec } { .pdfcvsall } ifelse
  492.     mark /pdfmark 3 -1 roll .pdfputparams
  493.     dup type /booleantype ne {
  494.       /pdfmark .pdfparamerror
  495.     } if cleartomark
  496.   } ifelse
  497. } odef
  498. userdict /pdfmark .undef
  499. currentdict /.pdfmarkparams .undef
  500.  
  501.  
  502. %    <dict> .hook_DSC_Creator -
  503. /.pdf_hook_DSC_Creator
  504. {
  505.   % If the Creator is PScript5.dll, disable the 32 /FontType resource for
  506.   % handling GlyphNames2Unicode. Since /FontType category can't redefine,
  507.   % we can do only with redefining the operator 'resourcestatus'.
  508.   currentdevice .devicename /pdfwrite eq {
  509.     /Creator .knownget {
  510.       (PScript5.dll) search {
  511.         pop pop
  512.         systemdict /resourcestatus dup
  513.         { dup /FontType eq 2 index 32 eq and {
  514.             pop pop false
  515.           } {
  516.             resourcestatus
  517.           } ifelse
  518.         } bind .makeoperator .forceput
  519.       } if
  520.       pop
  521.     } if
  522.   } {
  523.     pop
  524.   } ifelse
  525. bind def
  526.  
  527. % Use the DSC processing hook to pass DSC comments to the driver.
  528. % We use a pseudo-parameter named DSC whose value is an array:
  529. %    /key1 (value1) ... /type
  530. /.pdfdsc_dict 2 dict def
  531. /.pdfdsc {    % <file> <DSC string> <dsc dict> [<prev proc>] .pdfdsc -
  532.   0 get dup null ne { 4 copy exch pop exec pop } { pop } ifelse 3 -1 roll pop
  533.         % Stack: <dsc string> <dsc dict>
  534.   20 .localvmdict 1 index { 3 copy put pop pop } forall
  535.   3 -1 roll .parse_dsc_comments    % <dsc dict> <dict> <type>
  536.   1 index //.pdf_hook_DSC_Creator exec
  537.   dup /NOP ne 2 index length 1 gt or {    % Skip unparsed comments
  538.     PDFWRDEBUG { (**** DSC comment: ) print dup == 1 index === flush } if
  539.     exch mark 4 1 roll {
  540.         % mark <key1> <value1> ... <dsc dict> <type> <key> <value>
  541.       3 index 2 index known {    % Skip the DSC_struct entry
  542.         pop pop
  543.       } {
  544.         .pdfcvs 4 -2 roll
  545.       } ifelse
  546.     } forall exch pop counttomark .localvmarray astore
  547.     mark /DSC 3 -1 roll .pdfputparams
  548.     dup type /booleantype ne {
  549.       /DSC .pdfparamerror
  550.     } {
  551.       cleartomark
  552.     } ifelse
  553.   } {
  554.     pop pop pop
  555.   } ifelse
  556. } bind def
  557. currentdict /.pdf_hook_DSC_Creator undef
  558. /.initialize_dsc_parser where {
  559.   pop
  560.   3000 % priority 
  561.   {
  562.     currentglobal true setglobal
  563.     2 dict dup .initialize_dsc_parser readonly
  564.     currentuserparams /ProcessDSCComment get
  565.     1 array astore    % in case the value is executable
  566.     //.pdfdsc /exec load 4 array astore cvx readonly
  567.     << /ProcessDSCComment 3 -1 roll >> setuserparams
  568.     setglobal
  569.   } bind .schedule_init
  570. } if
  571.  
  572. % ---------------- {set,current}distillerparams ---------------- %
  573.  
  574. % Define setdistillerparams / currentdistillerparams.
  575. % Distiller parameters are currently treated as device parameters.
  576. /.distillerparamkeys mark
  577.         % General parameters -- all distillers
  578.   /ASCII85EncodePages { }
  579.   /AutoRotatePages { }
  580.   /Binding { }
  581.   /CompressPages { }
  582.   /DefaultRenderingIntent { }
  583.   /DetectBlends { }
  584.   /DoThumbnails { }
  585.   /ImageMemory { }
  586.   /LockDistillerParams { }
  587.   /LZWEncodePages { }
  588.   /OPM { }
  589.   /PreserveHalftoneInfo { }
  590.   /PreserveOPIComments { }
  591.   /PreserveOverprintSettings { }
  592.   /TransferFunctionInfo { }
  593.   /UCRandBGInfo { }
  594.   /UseFlateCompression { }
  595.         % General parameters -- PDF writer
  596.         % StartPage and EndPage are renamed because EndPage
  597.         % clashes with a page device parameter.
  598.   /CoreDistVersion { }
  599.   /CompatibilityLevel { }
  600.         % ****** NOTE: StartPage and EndPage are disabled because
  601.         % ****** EndPage clashes with a page device parameter.
  602. %  /EndPage { exch pop /PDFEndPage exch }
  603.     /PDFEndPage { pop pop }
  604. %  /StartPage { exch pop /PDFStartPage exch }
  605.     /PDFStartPage { pop pop }
  606.   /Optimize { }
  607.   /ParseDSCCommentsForDocInfo { }
  608.   /ParseDSCComments { }
  609.   /EmitDSCWarnings { }
  610.   /CreateJobTicket { }
  611.   /PreserveEPSInfo { }
  612.   /AutoPositionEPSFiles { }
  613.   /PreserveCopyPage { }
  614.   /UsePrologue { }
  615.   /OffOptimizations { }
  616.           % PDF/X parameters
  617.   /PDFXTrimBoxToMediaBoxOffset { }
  618.   /PDFXSetBleedBoxToMediaBox { }
  619.   /PDFXBleedBoxToTrimBoxOffset { }
  620.         % Color sampled image parameters
  621.   /ColorACSImageDict { }
  622.   /AntiAliasColorImages { }
  623.   /AutoFilterColorImages { }
  624.   /ColorImageDepth { }
  625.   /ColorImageDict { }
  626.   /DownsampleColorImages { }
  627.   /ColorImageDownsampleThreshold { }
  628.   /ColorImageDownsampleType { }
  629.   /EncodeColorImages { }
  630.   /ColorImageFilter { }
  631.   /ColorImageResolution { }
  632.         % Color processing parameters
  633.   /CalCMYKProfile { }
  634.   /CalGrayProfile { }
  635.   /CalRGBProfile { }
  636.   /sRGBProfile { }
  637.   /ColorConversionStrategy { }
  638.   /ConvertCMYKImagesToRGB { }
  639.   /ConvertImagesToIndexed { }
  640.         % Grayscale sampled image parameters
  641.   /GrayACSImageDict { }
  642.   /AntiAliasGrayImages { }
  643.   /AutoFilterGrayImages { }
  644.   /GrayImageDepth { }
  645.   /GrayImageDict { }
  646.   /DownsampleGrayImages { }
  647.   /GrayImageDownsampleThreshold { }
  648.   /GrayImageDownsampleType { }
  649.   /EncodeGrayImages { }
  650.   /GrayImageFilter { }
  651.   /GrayImageResolution { }
  652.         % Monochrome sampled image parameters
  653.   /AntiAliasMonoImages { }
  654.   /MonoImageDepth { }
  655.   /MonoImageDict { }
  656.   /DownsampleMonoImages { }
  657.   /MonoImageDownsampleThreshold { }
  658.   /MonoImageDownsampleType { }
  659.   /EncodeMonoImages { }
  660.   /MonoImageFilter { }
  661.   /MonoImageResolution { }
  662.         % Font embedding parameters
  663.   /AlwaysEmbed
  664.    { dup length 0 gt
  665.       { dup 0 get false eq
  666.          { dup length 1 sub 1 exch getinterval exch pop /~AlwaysEmbed exch
  667.          } if
  668.       } if
  669.    }
  670.   /NeverEmbed
  671.    { dup length 0 gt
  672.       { dup 0 get false eq
  673.          { dup length 1 sub 1 exch getinterval exch pop /~NeverEmbed exch
  674.          } if
  675.       } if
  676.    }
  677.   /CannotEmbedFontPolicy { }
  678.   /EmbedAllFonts { }
  679.   /MaxSubsetPct { }
  680.   /SubsetFonts { }
  681.   /DSCEncodingToUnicode { }
  682. .dicttomark readonly def
  683. /.distillerdevice
  684.  { currentdevice .devicename dup /pdfwrite eq exch /ps2write eq or
  685.     { currentdevice }
  686.     { /pdfwrite finddevice }
  687.    ifelse
  688.  } bind def
  689.  
  690. % Some badly designed PostScript files only expect the current/set
  691. % distillerparams operators to exist in a distiller. Since we have
  692. % this as a runtime option, we enable these operators IFF the
  693. % currentdevice is pdfwrite. Also, we mask their existence in 
  694. % systemdict so that 'where' and 'known' don't show them unless
  695. % the currentdevice is pdfwrite.
  696. /.setdistillerparams {        % <dict> setdistillerparams -
  697.   .distillerdevice //null false mark 4 index {
  698.     //.distillerparamkeys 2 index .knownget { exec } { pop pop } ifelse
  699.   } forall .putdeviceparamsonly
  700.   dup type /booleantype ne {
  701.     /setdistillerparams .pdfparamerror
  702.   } {
  703.     pop pop pop
  704.   } ifelse
  705. } odef
  706. /.currentdistillerparams {    % - currentdistillerparams <dict>
  707.   .distillerdevice //.distillerparamkeys .getdeviceparams .dicttomark
  708.         % Patch StartPage and EndPage
  709.         % ****** NOTE: StartPage and EndPage are disabled because
  710.         % ****** EndPage clashes with a page device parameter.
  711. %  begin /StartPage PDFStartPage /EndPage PDFEndPage
  712. %  currentdict dup /PDFStartPage undef /PDFEndPage undef
  713. %  def def currentdict end
  714. } odef
  715. /setdistillerparams {
  716.   currentdevice .devicename dup /pdfwrite ne exch /ps2write ne and {
  717.     /setdistillerparams /undefined signalerror
  718.   } if
  719.   .setdistillerparams
  720. } bind odef
  721. /currentdistillerparams {
  722.   currentdevice .devicename dup /pdfwrite ne exch /ps2write ne and {
  723.     /currentdistillerparams /undefined signalerror
  724.   } if
  725.   .currentdistillerparams
  726. } bind odef
  727.  
  728. % Patch 'where' so that the distiller operators are only visible
  729. % if the pdfwrite device is the current one.
  730. { currentdevice .devicename dup /pdfwrite eq exch /ps2write eq or{
  731.     .where
  732.   } {
  733.     .where pop dup //systemdict eq { pop false } { true } ifelse
  734.   } ifelse
  735. } bind
  736. { /currentdistillerparams /setdistillerparams /pdfmark }
  737. { .wheredict exch 2 index put } forall pop
  738.  
  739. % Patch 'known' to hide the systemdict version of distiller operators
  740. % unless the currentdevice is pdfwrite.
  741. /known {
  742.   /currentdistillerparams 1 index eq /setdistillerparams 2 index eq or 
  743.   /pdfmark 2 index eq or {
  744.     systemdict 2 index eq {    % only mask the operator in systemdict
  745.       known currentdevice .devicename dup /pdfwrite ne exch /ps2write ne and { pop false } if
  746.     } {
  747.       known
  748.     } ifelse
  749.   } {
  750.     known
  751.   } ifelse
  752. } .bind odef
  753.  
  754. % Create a table for translation DSC comments into Unicode UTF-16
  755. /.make_DSC_translation_table {        % <encoding> .make_DSC_translation_table <array>
  756.   dup type /stringtype eq {
  757.     cvn
  758.   } if
  759.   dup type /nametype eq {
  760.     /Encoding findresource
  761.   } if
  762.   dup length array exch                   % [out] [in]
  763.   0 1 2 index length 1 sub {              % [out] [in] i
  764.     dup 2 index exch get                       % [out] [in] i n
  765.     dup dup null eq exch /.notdef eq or {
  766.       pop -1
  767.     } {
  768.       dup //AdobeGlyphList exch .knownget {  % [out] [in] i n c
  769.       dup type dup /arraytype eq exch /packedarraytype eq or {
  770.         0 get % fixme: using the 1st char
  771.       } if
  772.       exch pop                               % [out] [in] i c
  773.       } {                                    % [out] [in] i n
  774.         (DSCEncoding defines a character that is not in AdobeGlyphList : ) 
  775.         exch .namestring concatstrings =
  776.         /.make_DSC_translation_table cvx /undefined signalerror 
  777.       } ifelse
  778.     } ifelse
  779.     3 index                                  % [out] [in] i c [out]
  780.     3 1 roll put                             % [out] [in]
  781.   } for
  782.   pop                                        % [out]
  783. } bind def 
  784.  
  785. 1000 % priority
  786. {
  787.   % Note, this may not work if the initial device is not pdfwrite
  788.   % and may require the use of -dProvideUnicode on the command line.
  789.   currentdevice .devicename /pdfwrite eq
  790.   systemdict /ProvideUnicode .knownget not { false } if or {
  791.     currentglobal true setglobal
  792.     systemdict /.setupUnicodeDecoder known {
  793.       /Unicode /Decoding resourcestatus {
  794.         pop pop
  795.         /Unicode /Decoding findresource
  796.         .setupUnicodeDecoder
  797.       } {
  798.         QUIET not {
  799.           (WARNING: /Unicode /Decoding resource is not accessible but it is useful for generating ToUnicode CMap.) =
  800.         } if
  801.       } ifelse
  802.     } if
  803.     setglobal
  804.   } if
  805. } bind .schedule_init
  806.  
  807. 1010 % priority
  808. {
  809.     % Set a predefined configuration in the distiller device (pdfwrite)
  810.     /PDFSETTINGS where { 
  811.       pop /PDFSETTINGS load 
  812.     } { 
  813.       currentdevice .devicename /ps2write eq { /PSL2Printer } { /default } ifelse
  814.     } ifelse
  815.     .distillersettings exch get
  816.     % Don't override parameters defined on the command line.
  817.     dup length .distillercommon length add dict begin
  818.     .distillercommon 2 {
  819.       {
  820.         systemdict 2 index known { pop pop } { def } ifelse
  821.       } forall
  822.     } repeat
  823.     currentdevice .devicename /pdfwrite eq {
  824.       systemdict /PDFX known systemdict /PDFA known or {
  825.       /DSCEncoding where {
  826.           /DSCEncoding get .make_DSC_translation_table
  827.           /DSCEncodingToUnicode exch def 
  828.         } if
  829.       } if
  830.     } if
  831.     currentdict end .setdistillerparams
  832.     .distillerdevice //null false mark .putdeviceparams 
  833.     dup type /booleantype eq not { cleartomark pop } if pop pop
  834. } bind .schedule_init
  835.  
  836. % Set a path to library files (ps2write)
  837. .defaultdevicename /ps2write eq {
  838.   mark
  839.   /OPDFReadProcsetPath
  840.   systemdict /OPDFReadProcsetPath .knownget dup {   % check for a value on the command-line
  841.     1 index () eq {
  842.       (Configuration warning : empty OPDFReadProcsetPath, will use defaults.) =
  843.       systemdict /OPDFReadProcsetPath undef
  844.       pop pop false
  845.     } if
  846.   } if
  847.   not {                                             % if necessary, compute a default
  848.     mark
  849.     (gs_mgl_e.ps) (gs_mro_e.ps) (gs_agl.ps) (opdfread.ps) % Reverse order !
  850.     () counttomark 1 sub {
  851.       exch
  852.       .libfile { .filename } { false } ifelse not {
  853.         (Configuration error : library file opdfread.ps not found !) =
  854.         (opdfread.ps) /undefinedfilename signalerror
  855.       } if
  856.       .filenamelistseparator concatstrings concatstrings
  857.     } repeat
  858.     exch pop
  859.   } if
  860.   %stack: mark /OPDFReadProcsetPath <filelist>
  861.   /ps2write finddevice putdeviceprops pop           % set the default instance's procset path
  862. } if
  863.  
  864. 2000 % priority
  865. { % Note, this may not work if the initial device is not pdfwrite
  866.   currentdevice .devicename dup /pdfwrite eq exch /ps2write eq or {
  867.     % Inform the device with initial graphic state. See gdev_pdf_fill_path.
  868.     newpath fill
  869.   } if
  870. } bind .schedule_init
  871.